<template>
  <div class="image-wrapper">
    <ws-image-viewer :images="images"></ws-image-viewer>
  </div>
</template>

<script>

import WsImageViewer from './ImageViewer'
import * as imageService from '@/api/services/imageService'

export default {
  name: 'WsImageApp',
  components: {
    WsImageViewer
  },
  data () {
    return {
      images: []
    }
  },
  computed: {
  },
  created () {
    this.doRefresh()
  },
  methods: {

    /**
     * 刷新数据
     */
    doRefresh () {
      this.$store.dispatch('listImages', {
        query: {
          path: 'Images'
        }
      }).then(response => {
        this.images = this.parseData(response.data)
      }).catch((e) => {
        console.log('catch', e)
      })
    },

    /**
     * 解析数据
     * @param {Array} data 数据
     */
    parseData (data) {
      data = data || []
      data.forEach(d => {
        d.url = imageService.getUrl(d.id)
      })
      return data
    }
  }
}
</script>
